package com.mylib.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mylib.libcore.R;
import com.mylib.libcore.utils.UIUtils;

/**
 * @author Administrator
 * @date 2019/12/20-9:38
 * @description CustomRadioText-自定义单选文字
 **/
public class CustomRadioText extends LinearLayout {
    private Context mContext;
    private View mView;
    private LinearLayout linearLayout;
    private ImageView imageView;
    private TextView textView;
    private boolean isSelect = false;



    public CustomRadioText(Context context) {
        this(context, null);
    }

    public CustomRadioText(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomRadioText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }




    private void init(Context context) {
        mContext = context;
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = inflater.inflate(R.layout.custom_radio_text_layout, this, true);
        linearLayout = (LinearLayout) mView.findViewById(R.id.ll_radio_text);
        imageView = (ImageView) mView.findViewById(R.id.iv_radio_img);
        textView = (TextView) mView.findViewById(R.id.tv_radio_text);
    }

    /**
     * 必须初始化
     */
    public void initCusRadioText(String title) {
        textView.setText(title+"");
    }

    public void setTextColor(int colorId) {
        textView.setTextColor(getResources().getColor(colorId));
    }


    public void setSelect() {
        isSelect = true;
        textView.setTextColor(getResources().getColor(R.color.color_sys));
        imageView.setImageResource(R.drawable.img_item_choosed);
    }
    
    public void setUnSelect() {
        isSelect = false;
        textView.setTextColor(getResources().getColor(R.color.text_color_b6));
        imageView.setImageResource(R.drawable.img_item_unchoose);
    }
    public void setClink(){
        if(!isSelect){
            setSelect();
        }else {
            setUnSelect();
        }
    }

    public boolean isSelect() {
        return isSelect;
    }

    public void setSelect(boolean select) {
        isSelect = select;
    }
}
